<?php

/*

Process Add Reply (add_reply.pro.php)

*/
ob_start();
$rank_check = 3;
include "global.inc.php";

if ($getInfo[premium] == "1")
{
	$colors = "$text_color, $bg_color, $bg_image.gif";
	$remember = fetch("SELECT background,text FROM remember_colors WHERE userid = '$userid'");
	if (($remember[background] != "$bg_color") OR ($remember[text] != "$text_color"))
	{
		$bg_color2 = ereg_replace("#", "", $bg_color);
		$text_color2 = ereg_replace("#", "", $text_color);

		mysql_query("DELETE FROM remember_colors WHERE userid = '$userid'");
		mysql_query("INSERT INTO remember_colors VALUES ('', '$userid', '$bg_color2', '$text_color2')");
	}
}

if (!$text_color) { $text_color = "#000000"; }

$add_reply = format(quote(smilies(badwords(strip_tags($add_reply,"<b><i><u><a><font><blockquote>")))),"$text_color");

if (!$add_reply)
{
	die(header(error("view_topic.php?game=$game&id=$reply_to", "Please do not leave the message blank.")));
}

mysql_query("INSERT INTO forum_replies2 (thread,message,author,posted_at,game,colors) VALUES ('$reply_to','$add_reply','$userid','$timestamp','$game','$colors')");

$findMessage = fetch("SELECT category,num_replies FROM forum_subjects2 WHERE id = '$reply_to' AND game = '$game'");
$findCat2 = fetch("SELECT posts FROM forum_cats2 WHERE id = '$findMessage[category]' AND game = '$game'");

mysql_query("UPDATE forum_cats2 SET last_post=$timestamp WHERE id = '$findMessage[category]' AND game = '$game'");
mysql_query("UPDATE forum_cats2 SET last_poster=$userid WHERE id = '$findMessage[category]' AND game = '$game'");
mysql_query("UPDATE forum_subjects2 SET last_post_at=$timestamp WHERE id = '$reply_to' AND game = '$game'");
mysql_query("UPDATE forum_subjects2 SET last_post_by=$userid WHERE id = '$reply_to' AND game = '$game'");
mysql_query("UPDATE members2 SET post_count=$getInfo[post_count]+1 WHERE username = '$username' AND game = '$game'");

header(error("view_topic.php?game=$game&id=$reply_to&page=$page","Your message has been posted."));

?>